import http from '@/utils/http'

const BASE_URL = '/{{.PackageName}}/{{.ModuleName}}'

export interface {{.ClassName}}Resp {
  {{ range .Columns -}}
  {{- if eq .GoField "CreatedAt" -}}
  {{- else if eq .GoField "UpdatedAt" -}}
  {{- else if eq .GoField "DeletedAt" -}}
  {{- else if eq .GoField "CreateBy" -}}
  {{- else if eq .GoField "UpdateBy" -}}
  {{ else if eq .GoType "time.Time" }} {{.JsonField}}: string
  {{ else if eq .GoType "int64" }} {{.JsonField}} : number
  {{ else if eq .GoType "string" }} {{.JsonField}} : string
  {{ else if eq .GoType "int" }} {{.JsonField}} : number
  {{ else }}
  {{.JsonField}} : string
  {{- end }}
{{- end }}
}
export interface {{.ClassName}}DetailResp {
  {{ range .Columns -}}
  {{- if eq .GoField "CreatedAt" -}}
  {{- else if eq .GoField "UpdatedAt" -}}
  {{- else if eq .GoField "DeletedAt" -}}
  {{- else if eq .GoField "CreateBy" -}}
  {{- else if eq .GoField "UpdateBy" -}}
  {{ else  if eq .GoType "time.Time" }} {{.JsonField}}: string
  {{ else  if eq .GoType "int64" }} {{.JsonField}} : number
  {{ else  if eq .GoType "string" }} {{.JsonField}} : string
  {{ else  if eq .GoType "int" }} {{.JsonField}} : number
  {{ else }}
  {{.JsonField}} : string
  {{- end }}
{{- end }}
}
export interface {{.ClassName}}Query {
  {{ range .Columns -}}
  {{$z := .IsQuery -}}
  {{- if ($z) }}
  {{- if eq .GoType "time.Time" -}} {{.JsonField}}: string
  {{ else  if eq .GoType "int64" -}} {{.JsonField}} : number
  {{ else  if eq .GoType "string" -}} {{.JsonField}} : string
  {{ else  if eq .GoType "int" -}} {{.JsonField}} : number
  {{ else -}}
  {{.JsonField}} : string
  {{- end }}
  {{- end }}
  {{- end }}
  sort: Array<string>
}
export interface {{.ClassName}}PageQuery extends {{.ClassName}}Query, PageQuery {}

/** @desc 查询{{.TableComment}}列表 */
export function list{{.ClassName}}(query: {{.ClassName}}PageQuery) {
  return http.get<PageRes<{{.ClassName}}Resp[]>>(`${BASE_URL}`, query)
}

/** @desc 查询{{.TableComment}}详情 */
export function get{{.ClassName}}(id: string) {
  return http.get<{{.ClassName}}DetailResp>(`${BASE_URL}/${id}`)
}

/** @desc 新增{{.TableComment}} */
export function add{{.ClassName}}(data: any) {
  return http.post(`${BASE_URL}`, data)
}

/** @desc 修改{{.TableComment}} */
export function update{{.ClassName}}(data: any, id: string) {
  return http.put(`${BASE_URL}/${id}`, data)
}

/** @desc 删除{{.TableComment}} */
export function delete{{.ClassName}}(id: string) {
  return http.del(`${BASE_URL}/${id}`)
}

/** @desc 导出{{.TableComment}} */
export function export{{.ClassName}}(query: {{.ClassName}}Query) {
  return http.download<any>(`${BASE_URL}/export`, query)
}
